package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import zipkin2.Call;

import java.util.List;

@Api(tags = "品牌管理")
@RequestMapping("/admin/product")
@RestController
public class BaseTrademarkController {



    @Autowired
    BaseTrademarkService baseTrademarkService;

    @ApiOperation("获取所有品牌，在添加spu页面会用到")
    @GetMapping("baseTrademark/getTrademarkList")
    public Result getTrademarkList() {
        List<BaseTrademark> list = baseTrademarkService.list();
        return Result.ok(list);
    }

    @ApiOperation("修改品牌")
    @PutMapping("baseTrademark/update")
    public Result updateTrademark(@RequestBody BaseTrademark baseTrademark) {
        boolean b = baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("根据id获取品牌")
    @GetMapping("baseTrademark/get/{id}")
    public Result getBaseTrademarkById(@PathVariable("id") Long id) {
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }

    @ApiOperation("删除品牌")
    @DeleteMapping("baseTrademark/remove/{id}")
    public Result deleteBaseTrademarkById(@PathVariable("id") Long id) {
        boolean b = baseTrademarkService.removeById(id);
        return Result.ok();

    }


    @ApiOperation("添加品牌")
    @PostMapping("baseTrademark/save")
    public Result saveBaseTrademark(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.save(baseTrademark);
        return Result.ok();
    }

    @ApiOperation("获取品牌分页列表")
    @GetMapping("baseTrademark/{page}/{limit}")
    public Result getBaseTrademarkList(@PathVariable Long page, @PathVariable Long limit) {

        Page<BaseTrademark> pageParam = new Page<>(page,limit);
        Page<BaseTrademark> pageResult = baseTrademarkService.page(pageParam);
        return Result.ok(pageResult);
    }
}
